<?php
class Admin_Model_DbTable_country extends Zend_Db_Table_Abstract
{
	 protected $_name = 'hae_bdd_country';
	 protected $_sequence=true;
     protected $_primary='id';
     protected $_dependentTables=array('Admin_Model_DbTable_city','Admin_Model_DbTable_region');
	public function addCountry($name_vi, $name_en, $name_ja, $name_cn, $name_fr)
	{
		$data = array(
		'name_vi' => $name_vi,
		'name_en' => $name_en,
		'name_ja' => $name_ja,
		'name_cn' => $name_cn,
		'name_fr' => $name_fr,
		);
		$this->insert($data);
	}
	public function getCountry($id)
	{
	    $id = (int)$id;
	    $row = $this->fetchRow('id=' . $id);
		if(!$row)
		{ 
			throw  new Exception("Could not find row {$id}");
		}
		return $row->toArray();
	}
	public function getAllCountry()
	{
		try {
			$select = $this->select();
			$select->from($this->_name,array("id","name_en"));
			return $this->fetchAll($select);			
		}catch (Zend_Exception $e)
		{
			echo $e->getMessage();
		}
	}
	public function getListCity($id)
	{
		try {
			$row= $this->find($id);
			if($row->count() > 0)
			{
				$select=$this->select();
				$select->from("hae_bdd_city",array("id","name_en"));
				return $row->current()->findDependentRowset('Admin_Model_DbTable_city',NULL,$select);
			}
			return NULL;
		}catch(Zend_Exception $e)
		{
			echo $e->getMessage();
		}
	}
	public function getListRegion($id)
	{
		try {
			$row=$this->find($id);
			if($row->count() > 0)
			{
				$select=$this->select();
				$select->from("hae_bdd_region",array("id","name_en"));
				return $row->current()->findDependentRowset("Admin_Model_DbTable_region",NULL,$select);
			}
		}catch(Zend_Exception $e)
		{
			
		}
	}
	public function updatecountry($id, $name_vi, $name_en, $name_ja, $name_cn, $name_fr)
	{
		$data = array(
		'name_vi' => $name_vi,
		'name_en' => $name_en,
		'name_ja' => $name_ja,
		'name_cn' => $name_cn,
		'name_fr' => $name_fr,
		);
		$this->update($data, 'id = '. (int)$id);
	}
	public function changestatus($id,$status)
	{
		$data = array(
		'status' => $status,
		);
		$this->update($data, 'id = '. (int)$id);
	}
	public function deletecountry($id)
    {
        return $this->delete('id =' . (int)$id);
    }
}
?>